/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cs;

import java.util.Scanner;

/**
 *
 * @author QuangHieu
 */
public class myList {
    int spt;
    int a[];

    myList(){
        spt=0;  a=new int[100+1];
    }

    void append(int x){
        if(spt==a.length-1){
            int b[]=new int[2*spt+1];
            for(int i=0;i<spt;i++)
                b[i]=a[i];
            a=b;
        }
        spt++;  a[spt]=x;
    }

    void add(int x, int vt){
        if(spt ==a.length-1){
            System.out.print("\n List Is Full");
            int b[]=new int [spt*2+1];
            for(int i=1;i<spt;i++){
                b[i]=a[i];
            }
            a=b;
        }
        //dich cac phan tu sang phai 1 o ke tu vi tri vt
        for(int j=spt;j>=vt;j--)
            a[j+1]=a[j];
        a[vt]=x;
        spt++;
    }
    void taoDanhSach(){
        myList l=new myList();
        Scanner k=new Scanner(System.in);
        int x,i=1;
        do{
            System.out.print("\nNhap phan tu thu "+ i + ":");
            x=k.nextInt();
            if(x>0)l.append(x);
        }while(x<=0);
    }

    public void xoa(int index){
        for(int i=index;i<spt+1;i++)
            a[i]=a[i+1];
        spt--;
    }

    public void SapXep(){
        for(int i=1;i<spt;i++)
            for(int j=i+1;j<spt+1;j++)
                if(a[i]>a[j]){
                    int h=a[i];
                    a[i]=a[j];
                    a[j]=h;
                }
    }

    public void xoaTrung(){
        SapXep();
        for(int i=1;i<spt+1;i++)
            if(a[i+1]==a[i])
                xoa(i+1);
    }

    public boolean kiemTraTang(){
        for(int i=1;i<spt+1;i++)
            if(a[i+1]<a[i])
                return false;
        return true;
    }

    public boolean kiemTraDoiSung(){
        for(int i=1;i<(spt+1)/2;i++)
            if(a[i]!=spt+1-i)
                return false;
        return true;
    }

    public void daoDanhSach(){
        for(int i=1;i<(spt+1)/2;i++){
            int h=a[i];
            a[i]=a[spt+1-i];
            a[spt+1-i]=h;
        }
    }

    public void tachDanhSach(){

    }

    public String toString(){
        String t="[";
        for(int i=1;i<=spt;i++)
            t=t+a[i]+";";
        t=t+"]";
        return t;
    }

    public static void main(String args[]){
        myList l=new myList();
        for(int i=0;i<=10;i++)
            l.append((int)(Math.random()*100));
        System.out.print("\n Danh sach la: "+l+"\n");
       // l.xoaTrung();
        l.daoDanhSach();
        System.out.print("\n Danh sach la: "+l+"\n");
    }
}
